//
//  DesTripPhotoCollectionViewCell.m
//  HappyTrip
//
//  Created by yuxuesong on 15-3-25.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "DesTripPhotoCollectionViewCell.h"

@implementation DesTripPhotoCollectionViewCell

- (void)dealloc
{
//    [_titleLabel release];
    [_textView release];
    [_tripImageView release];
    [_desTripPhotoObject release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.tripImageView = [[UIImageView alloc] init];
        _tripImageView.contentMode = UIViewContentModeScaleAspectFit;
        [self.contentView addSubview:_tripImageView];
        [_tripImageView release];
        
        
        self.titleLabel = [[UILabel alloc] init];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.font = [UIFont systemFontOfSize:17];
        _titleLabel.textColor = [UIColor lightGrayColor];
//        _titleLabel.backgroundColor = [UIColor clearColor];
        [self.contentView addSubview:_titleLabel];
        [_titleLabel release];
        
        self.textView = [[UITextView alloc] init];
        _textView.userInteractionEnabled = NO;
        _textView.textColor = [UIColor lightGrayColor];
        _textView.backgroundColor = [UIColor blackColor];
        _textView.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:_textView];
        [_textView release];
    }
    return self;
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    CGFloat width = layoutAttributes.bounds.size.width;
    CGFloat height = layoutAttributes.bounds.size.height;
    self.titleLabel.frame = CGRectMake(0, 0, width, height / 10);
    self.tripImageView.frame = CGRectMake(0, height / 10, width, height * 7 / 10);
    self.textView.frame = CGRectMake(width / 20, height * 8 / 10 + 10, width - width / 20 * 2, height * 2 / 10);
}

- (void)setDesTripPhotoObject:(DesTripPhotoObject *)desTripPhotoObject
{
    if (_desTripPhotoObject != desTripPhotoObject) {
        [_desTripPhotoObject release];
        _desTripPhotoObject = [desTripPhotoObject retain];
    }
    self.smallPic.image = [UIImage imageNamed:@"placeholder.jpg"];
    [self.tripImageView setImageWithURL:[NSURL URLWithString:self.desTripPhotoObject.photo] placeholderImage:[UIImage imageNamed:@"picLoading.png"]];
    self.textView.text = self.desTripPhotoObject.text;
    self.titleLabel.text = self.desTripPhotoObject.trip_name;
}

@end
